package edu.sctu.zhengsenwen.month201506.day20150616.network;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by user15 on 2015/6/18.
 */
public class HttpPost {

    public static String getSend(String path,String param) throws IOException {

        PrintWriter output = null;
        BufferedReader input = null;
        String result = "";

        try{
            URL url = new URL(path);

            URLConnection urlConnection = url.openConnection();
            urlConnection.setRequestProperty("access","**");
            urlConnection.setRequestProperty("content","&&");
            urlConnection.setRequestProperty("connection","Keep-Alive");
            urlConnection.setRequestProperty("user-agent","Mozilla/4.0(compatible;MSIE 6.0; Windows NT 5.1;SV1)");


            urlConnection.setDoInput(true);
            urlConnection.setDoOutput(true);

            output = new PrintWriter(urlConnection.getOutputStream());
            output.print(param);
            output.flush();

            input = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

            String line;
            while((line = input.readLine()) != null){
                 result = line;
            }

        }catch (Exception ex){
            System.out.println("输出异常");
            ex.printStackTrace();
        }


        finally{
            try{
                if(output != null){
                    output.close();
                }

                if(input != null){
                    input.close();
                }

            }catch (Exception ex){
                ex.printStackTrace();
            }
        }
        return result;
    }

    public static void main(String[] args) throws IOException {
        String string = HttpPost.getSend("******","********");
        System.out.println(string);
    }
}
